package com.klun.hdfs.hd.reducer;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {

    int sum;
    IntWritable v = new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> value, Context context) throws IOException, InterruptedException {
        // 累加求和
        sum = 0;
        for(IntWritable count:value){
            sum += count.get();
        }
        // 输出
        v.set(sum);
        context.write(key,v);
    }
}
